﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class RectGuide : GuideBase, ICanvasRaycastFilter
{
    public override GuideType guideType => GuideType.Rect;

    private float width;        // 镂空区域的宽
    private float height;       // 镂空区域的高

    // 引导
    public override void Guide(RectTransform target)
    {
        //调用下base,中的方法
        base.Guide(target);
        // 中心点的计算在base.Guide(canvas,target)有了，
        // 计算宽高
        width = (targetCorners[3].x - targetCorners[0].x) / 2;
        height = (targetCorners[1].y - targetCorners[0].y) / 2;
        //设置材质的宽高
        material.SetFloat("_SliderX", width);
        material.SetFloat("_SliderY", height);
    }

    private void OnDisable()
    {
        material.SetFloat("_SliderX", 0);
        material.SetFloat("_SliderY", 0);
    }

    public bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
    {
        return !RectTransformUtility.RectangleContainsScreenPoint(target, sp, eventCamera);
    }
}